$(function() {
    //主流程对象
    var mainCtrl = avalon.define({
        $id: "mainController",
        staffId: "",
        startTime: getMinDate(-30),
        endTime: getMinDate(0),
        recordCount: 0,
        exportObj: {
            staffId: "",
            endTime: "",
            startTime: ""
        },
        exportRecord: function() {
            window.location = DI.exportRecord + "?staffId=" + mainCtrl.exportObj.staffId + "&endTime=" + mainCtrl.exportObj.endTime + "&startTime=" + mainCtrl.exportObj.startTime;
        },
        searchRecordList: function() {
            var searchParam = {
                "pageNo": 1,
                "pageSize": 10,
                "staffId": mainCtrl.staffId,
                "endTime": mainCtrl.endTime,
                "startTime": mainCtrl.startTime
            }
            mainCtrl.exportObj = {
                staffId: mainCtrl.staffId,
                endTime: mainCtrl.endTime,
                startTime: mainCtrl.endTime
            }
            taskTable.search(searchParam);
            
            getRecordCount();
        }
    });

    //表格实例化
    var taskTable = null;
    var opts = {
        targetId: "taskTable",
        templateId: "tableTask",
        settings: {
            url: DI.queryRecordList_innerCoupon,
            ajaxType: "json",
            sourceInterface: {
                INum: "totalSize",
                IData: "records"
            },
            paginationIndexName: {
                "peerpageRows": "pageSize",
                "currentPage": "pageNo"
            },
            searchParam: {
                "staffId": "",
                "endTime": mainCtrl.endTime,
                "startTime": mainCtrl.startTime
            }
        }

    };
    mainCtrl.exportObj = {
        staffId: mainCtrl.staffId,
        endTime: mainCtrl.endTime,
        startTime: mainCtrl.startTime
    }
    taskTable = SwiftUI.swiftTable.getInstance(opts);
    getRecordCount();

    function getRecordCount() {
        var intervalSource = setInterval(function() {
            mainCtrl.recordCount = taskTable.table.$model.returnData.data.recordCount;
            if(mainCtrl.recordCount != 0) {
                clearInterval(intervalSource);
            }
        }, 100);
    }
    //实例化时间
    PLATFORM.datepickerRange("#starttime", "#endtime");

    avalon.scan();
});